package com.sanjiahantang.youjiarole.module.join.views.impl;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.Lable;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.config.SPConfig;
import com.sanjiahantang.youjiarole.utils.SPUtils;

import java.util.ArrayList;

/**
 * Created by zy on 2017/10/26.
 */

public class RoleTypeSelectorActivity extends BaseMvpActivity implements BaseView, View.OnClickListener {


    private Lable lbSelector;
    private String rolePassed;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public BaseMvpPresenter initPresenter() {
        return new BaseMvpPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_label_selector);
        lbSelector = (Lable) findViewById(R.id.lbSelector);
        rolePassed = SPUtils.get(this, SPConfig.ROLE_ID,"").toString();
        ArrayList<String> list = (ArrayList<String>) getIntent().getSerializableExtra("list");
        lbSelector.setDataList(list);

        String param = getIntent().getStringExtra(KEY_PARAM);
        if (!TextUtils.isEmpty(param)){
            lbSelector.setSelectBytext(param.split(","));
        }

        TextView title = (TextView) findViewById(R.id.title);
        title.setText("选择申请角色");

        findViewById(R.id.flIcon3).setVisibility(View.VISIBLE);
        findViewById(R.id.flIcon3).setOnClickListener(this);
        findViewById(R.id.fl_Left).setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.flIcon3:
                Intent intent = new Intent();
                int max = lbSelector.getSelectContent().size();
                String role = "";
                if (max > 0){
                    for (int i = 0;i<max;i++){
                        role += lbSelector.getSelectContent().get(i) + ",";
                    }
                    role = role.substring(0,role.length() - 1);
                    if (role.contains("体验店")){
                        boolean valid = true;
                        if (role.contains("设计师") || rolePassed.contains("0")){
                            valid = valid && true;
                        }else{
                            valid = valid && false;
                        }

                        if (role.contains("项目经理") || rolePassed.contains("1")){
                            valid = valid && true;
                        }else{
                            valid = valid && false;
                        }

                        if (!valid){
                            Utils.showToast($this,"选择申请体验店必须申请设计师和项目经理!");
                            return;
                        }
                    }
                }



                intent.putExtra(KEY_PARAM,role);
                setResult(RESULT_OK,intent);
                finish();
                break;
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
